package com.cc.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.cc.entity.UserStudent;

public class LoginInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		// TODO Auto-generated method stub
		response.setHeader("Access-Control-Allow-Credentials", "true");
		HttpSession session=request.getSession();
		System.out.println("++++++++++++pre+++++++++++++");
		String url=request.getRequestURI();
		String ctx=request.getContextPath();
		//url含有private表明需要登录访问，进行拦截
		if(!url.contains("private")){
			return true;//不拦截其他请求
		}
		Object token=request.getSession().getId();
		System.out.println("++++++++++++"+session.getId()+"+++++++++++++");
//		if(token!=null)
//		return true;
//		else
//		return false;	
		return true;
	}
	
	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("++++++++++++post+++++++++++++");
	}
	
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		System.out.println("++++++++++++after+++++++++++++");
	}

}
